<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .wrap {
            width: 600px;
            margin: 0 auto;
            margin-top: 50px;
        }

        .nav {
            text-align: center;
            line-height: 40px;
            display: flex;
        }

        .nav li {
            flex: 1;
            border: 1px solid #333;
        }

        .nav li+li {
            border-left: 0;
        }

        .nav .active {
            background-color: pink;
            color: #fff;
        }

        .tabCon {
            height: 400px;
            /* border: 1px solid #333;
            border-top: 0; */
        }

        .tabCon .part {
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            text-align: center;
            line-height: 400px;
            border: 1px solid #333;
            border-top: 0;
            display: none;
        }

        .tabCon .show {
            display: block;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <ul class="nav">
            <li class="active">nav_01</li>
            <li>nav_02</li>
            <li>nav_03</li>
            <li>nav_04</li>
            <li>nav_05</li>
            <li>nav_06</li>
        </ul>
        <div class="tabCon">
            <div class="part show">part_01</div>
            <div class="part">part_02</div>
            <div class="part">part_03</div>
            <div class="part">part_04</div>
            <div class="part">part_05</div>
            <div class="part">part_06</div>
        </div>
    </div>
</body>
<script>
    // 点击导航 => 被点击的导航变为活跃状态,其他导航回归默认样式
    // (1) 每次点击 先清除上一个被点击的导航的样式  再把当前的导航变为活跃状态
    // (2) 不管之前哪一个被点击 => 清除所有导航的活跃状态的样式 => 再把自己变为活跃状态

    var liList = document.querySelectorAll(".nav li");
    var partList = document.querySelectorAll(".tabCon .part");

    for (let i = 0; i < liList.length; i++) {
        let li = liList[i];
        li.onclick = function () {
            // debugger; // 点击时触发

            // 清除所有导航的活跃状态的样式  tab栏全部隐藏
            for (var j = 0; j < liList.length; j++) {
                liList[j].className = "";
                partList[j].classList.remove("show");
            }
            // this.className = "active";  // 被点击的导航变为活跃状态
            liList[i].className = "active";  // 被点击的导航变为活跃状态
            partList[i].classList.add("show"); // 对应下标的tab栏显示
        }
    }




</script>

</html>